package com.wsd.serviceImpl;

import com.wsd.dao.LoanInformationMapper;
import com.wsd.dao.RepaymentPlanMapper;
import com.wsd.domain.NormalLoan;
import com.wsd.service.NormalLoanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Classname NormalLoanServiceImpl
 * @Description TODO
 * @Date 2020/7/20 10:02
 * @Created by niuxiaojuan
 */
@Service
public class NormalLoanServiceImpl implements NormalLoanService {

    @Autowired
    RepaymentPlanMapper repaymentPlanMapper;
    @Autowired
    LoanInformationMapper loanInformationMapper;

    @Override
    //正常贷款放款总额：显示所有贷款金额总数。
    public BigDecimal sumNormalLoan(){
        List<Long> list=repaymentPlanMapper.findNormalGroup();
        return loanInformationMapper.sumLoanMoney(list);
    }

    @Override
    //正常贷款已还总额（不含利息）：用户已经还清的本金的总额//正常贷款已还总额（不含利息）：用户已经还清的本金的总额。
    public BigDecimal sumRepayLoanMoney()
    {
        List<Long> list=repaymentPlanMapper.findNormalGroup();
        BigDecimal remianMoney=loanInformationMapper.sumRemainPrincipal(list);
        return loanInformationMapper.sumLoanMoney(list).subtract(remianMoney);
    }

    @Override
    //
    public BigDecimal findNormalInterest() {
        return repaymentPlanMapper.findNormalInterest();

    }

    @Override
    public BigDecimal sumRepayInterest() {
        return repaymentPlanMapper.sumRepayInterest(repaymentPlanMapper.findNormalGroup());
    }

    @Override
    public List<NormalLoan> findNormalLoanForm(int pagenum,int num) {
        List<NormalLoan> list=repaymentPlanMapper.findNormalLoanForm((pagenum-1)*num,num);
        for(NormalLoan n:list)
        {
            NormalLoan temp=loanInformationMapper.findFormInfoById(n.getLoanId());
            n.setUserId(temp.getUserId());
            n.setLoanAmount(temp.getLoanAmount());
            n.setRepayAmount(temp.getRepayAmount());
        }
        return list;
    }

    @Override
    public Long countNormalLoanForm() {
        return repaymentPlanMapper.countNormalLoanForm();
    }

    /*@Override
    public NormalLoan findFormInfoById(Long loanId) {
        return loanInformationMapper.findFormInfoById(loanId);
    }*/


}
